﻿@model SCMS.UI.Models.ReviewOR           
@{
    string action = "";
    string headerText = "";
    string successMsg = "";        
    if (Model.IsFinanceReview)
    {
        action = "ReviewOrder";
        successMsg = "Order Request financially reviewed successfully.";
        headerText = "Order Request Financial Review";
    }
    else
    {
        action = "ApproveOrder";
        successMsg = "Order Request approved successfully.";
        headerText = "Order Request Approval";
    }
    AjaxOptions ajaxOpts = new AjaxOptions
      {
          UpdateTargetId = "popup-page",
          LoadingElementId = "popup-loading",
          HttpMethod = "Post",
          Url = Url.Action(action),
          OnBegin = "return VerifyBLBalance(" + Model.ORItems.Count + ")",
          OnSuccess = "ReviewComplete('" + successMsg + "', 'Approval Complete')"
      };
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

<div class="partialViewCard" style="max-width: 1000px;">
    <div class="partialViewCardHeader"><h3>@headerText</h3></div>
    <br />
    @using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
    {
        @Html.ValidationSummary(true)        
        <h4 style="text-align: center;">@Model.ORequest.OrderRequestNo</h4>
        <table width="98%" align="center">
            <tr class="gridheader">
                <th width="33.3%">
                    Order Request Number
                </th>
                <th width="33.3%">
                    Date
                </th>
                <th width="33.3%">
                    Currency of OR
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Model.ORequest.OrderRequestNo
                    @Html.HiddenFor(m => m.ORequest.EntityOrderRequest.Id)
                </td>
                <td align="center">
                    @Model.ORequest.IssueDate.ToString("dd/MM/yyyy")
                    @Html.HiddenFor(m => m.ORequest.EntityOrderRequest.OrderDate)
                </td>
                <td align="center">
                    @foreach (var curr in Model.ORequest.currencies)
                    {
                        if (curr.Value == Model.ORequest.EntityOrderRequest.CurrencyId.ToString())
                        { 
                            @curr.Text
                            break;
                        }
                    }    
                    @Html.HiddenFor(x => x.ORequest.EntityOrderRequest.CurrencyId, new { @id = "currencyId" })
                </td>
            </tr>
            <tr class="gridheader">
                <th>
                    Program
                </th>
                <th>
                    Project
                </th>
                <th>
                    Donor
                </th>
            </tr>
            <tr>
                <td align="center">
                    @foreach (var proj in Model.ORequest.Projects)
                    {
                        if (proj.Value == Model.ProjectId.ToString())
                        { 
                            @proj.Text
                            break;
                        }
                    } 
                </td>
                <td align="center">
                    @foreach (var proj in Model.ORequest.ProjectNos)
                    {
                        if (proj.Value == Model.ProjectDonorId.ToString())
                        { 
                            @proj.Text
                            break;
                        }
                    } 
                </td>
                <td align="center">
                   <div id="donorDiv">
                        @Html.DisplayFor(x => x.ORequest.EntityOrderRequest.ProjectDonor.Donor.Name)
                    </div>
                </td>
            </tr>
            <tr class="gridheader">
                <th>
                    Requested Delivery Date
                </th>
                <th>
                    Requested Delivery Destination
                </th>
                <th>
                    Final Delivery Destination
                </th>
            </tr>
            <tr>
                <td align="center">
                    @Model.ORequest.RequestDate.ToString("dd/MM/yyyy")
                    @Html.HiddenFor(m => m.ORequest.EntityOrderRequest.DeliveryDate)
                </td>
                <td align="center">
                    @foreach (var dest in Model.ORequest.RequestDelivLocations)
                    {
                        if (dest.Value == Model.ORequest.EntityOrderRequest.RequestedDestinationId.ToString())
                        { 
                            @dest.Text
                            break;
                        }
                    } 
                </td>
                <td align="center">
                    @foreach (var dest in Model.ORequest.FinalDelivLocations)
                    {
                        if (dest.Value == Model.ORequest.EntityOrderRequest.FinalDestinationId.ToString())
                        { 
                            @dest.Text
                            break;
                        }
                    }
                </td>
            </tr>
        </table>
        <hr />
            <h4>&nbsp;&nbsp;Order Request Items</h4>
        <p>&nbsp;&nbsp;Specification/Description, Unit, Quantities, Estimated Prices & PN/BL</p>
        <p id="budgetCheckStatus"></p>
        <table width="98%" align="center" border="1" style="border: 1px solid grey; border-collapse: collapse; font-size: 12px;">
            <tr class="gridheader">
                <th width="5%">No.</th>
                <th width="10%">Item</th>
                <th width="20%">Description</th>
                <th width="10%">Unit</th>
                <th width="10%">Qty</th>
                <th width="10%">Estimated Unit Price</th>
                <th width="10%">Estimated Total Price</th>
                <th width="10%">BL</th>
                <th width="10%">Remarks</th>
            </tr>
            @{int num = 0; string pbDiv = ""; string rowId = "";}
            @for (int i = 0; i < Model.ORItems.Count; i++)
            {
                num = i + 1;
                pbDiv = "PBlines" + num;
                rowId = "row" + i;
                <tr class="gridodd" id="@rowId">
                    <td align="right">
                        @num                   
                    </td>
                    <td>
                        @Model.ORItems[i].EntityOrderRequestItem.Item.Name
                    </td>
                    <td>
                        @Html.DisplayFor(item => Model.ORItems[i].Description)
                        @Html.HiddenFor(item => Model.ORItems[i].OrderRequestItemId)
                    </td>
                    <td align="center">
                        @foreach (var uom in Model.ORItems[i].UnitMessures)
                        {
                            if (uom.Value == Model.ORItems[i].UnitMessureID)
                            { 
                                @uom.Text
                                break;
                            }
                        }    
                    </td>
                    <td>@Html.TextBoxFor(item => Model.ORItems[i].Quantity, new { @class = "numericTb", @id = "qty" + i, onblur = "calculateTotals(" + i + ", " + Model.ORItems.Count + ")" })</td>
                    <td>@Html.TextBoxFor(item => Model.ORItems[i].UnitPrice, new { @class = "numericTb", @id = "unitPrice" + i, onblur = "calculateTotals(" + i + ", " + Model.ORItems.Count + ")" })</td>
                    <td>
                        @Html.TextBoxFor(item => Model.ORItems[i].TotalPrice, new { @class = "numericTb", @id = "totalPrice" + i, @readonly = "readonly" })
                    </td>                
                    <td>
                        <div id="@pbDiv">
                            @Html.DropDownListFor(item => Model.ORItems[i].BudgetLineID, Model.ORItems[i].BudgetLines, new { @class = "smallControl", onchange = "javascript:checkBalance4Review(this, '')" })     
                        </div>
                    </td>
                    <td>@Html.TextBoxFor(item => Model.ORItems[i].Remarks, new { @class = "smallControl", @readonly = "readonly" })</td>
                </tr>
            }
            <tr>
                <td colspan="3" class="gridheader3" align="right">Currency of Order Request:&nbsp;</td>
                <td align="center">@Model.ORequest.EntityOrderRequest.Currency.ShortName</td>
                <td class="gridheader3" align="right" colspan="2">Total:&nbsp;</td>
                <td>@Html.TextBoxFor(m => m.ORequest.EntityOrderRequest.TotalAmount, new { @class = "numericTb", @readonly = "readonly", @id = "totalVal" })</td>
                <td colspan="2" class="gridheader3">OR Value</td>
            </tr>
            @if (Model.IsFinanceReview)
            {
                <tr>
                    <td colspan="3" class="gridheader3" align="right">Master Budget Currency:&nbsp;</td>
                    <td align="center">
                        @foreach (var curr in Model.Currencies)
                        {
                            if (curr.Value == Model.MBCurrencyId)
                            { 
                                @curr.Text                               
                           break;
                            }
                        } 
                        @Html.HiddenFor(m => m.MBCurrencyId, new { id = "mbCurrencyId" })                        
                    </td>
                    <td class="gridheader3" align="right" colspan="2">Total:&nbsp;</td>
                    <td>
                        @Html.TextBoxFor(item => Model.MbValue, new { @class = "numericTb", @id = "mbValue" })
                        <input type="hidden" id="origLocalValue" />
                        <input type="hidden" id="origFxValue" />
                    </td>
                    <td colspan="2" class="gridheader3">OR Value</td>
                </tr>
            }
            else
            { 
                <input type="hidden" id="mbCurrencyId" value="@Model.MBCurrencyId" />
            }
        </table>
        <br />
        <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
            <tr class="gridheader">
                <td width="16%">
                    Authorization
                </td>
                <td width="21%">
                    Authorized Requestor
                </td>            
                <td width="21%">
                    Approved By
                </td>
                <td width="21%">
                    Finance Review of BL/PN
                </td>
                <td width="21%">
                    Authorized by Manager/CD
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Name:
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff2 != null)
                    {
                        @Model.ORequest.EntityOrderRequest.Staff2.Person.FirstName 
                        @Html.Raw("&nbsp;")
                        @Model.ORequest.EntityOrderRequest.Staff2.Person.OtherNames
                    }
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff != null)
                    { 
                        @Model.ORequest.EntityOrderRequest.Staff.Person.FirstName
                        @Html.Raw("&nbsp;")
                        @Model.ORequest.EntityOrderRequest.Staff.Person.OtherNames
                    }
                    &nbsp;
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff3 != null)
                    {
                        @Model.ORequest.EntityOrderRequest.Staff3.Person.FirstName 
                        @Html.Raw("&nbsp;")
                        @Model.ORequest.EntityOrderRequest.Staff3.Person.OtherNames
                    }   
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff1 != null)
                    {
                        @Model.ORequest.EntityOrderRequest.Staff1.Person.FirstName 
                        @Html.Raw("&nbsp;")
                        @Model.ORequest.EntityOrderRequest.Staff1.Person.OtherNames
                    }   
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Title:
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff2 != null)
                    {
                        @Model.ORequest.EntityOrderRequest.Staff2.Designation.Name
                    }
                </td>
            
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff != null)
                    { 
                        @Model.ORequest.EntityOrderRequest.Staff.Designation.Name
                    }
                    &nbsp;
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff3 != null)
                    {
                        @Model.ORequest.EntityOrderRequest.Staff3.Designation.Name
                    }   
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff1 != null)
                    {
                        @Model.ORequest.EntityOrderRequest.Staff1
                    }   
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Date:
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff2 != null)
                    {
                        @Model.ORequest.EntityOrderRequest.PreparedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                    }
                </td>            
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff != null)
                    { 
                        @Model.ORequest.EntityOrderRequest.ApprovedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                    }
                    &nbsp;
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff3 != null)
                    {
                        @Model.ORequest.EntityOrderRequest.ReviewedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                    }
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff1 != null)
                    {
                        @Model.ORequest.EntityOrderRequest.AuthorizedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                    }
                </td>
            </tr>
            <tr>
                <td class="gridheader">
                    Signature:
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff2.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.ORequest.EntityOrderRequest.Staff2.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                </td>            
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.ORequest.EntityOrderRequest.Staff.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                    &nbsp;
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff3 != null && Model.ORequest.EntityOrderRequest.Staff3.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.ORequest.EntityOrderRequest.Staff3.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                </td>
                <td>
                    @if (Model.ORequest.EntityOrderRequest.Staff1 != null && Model.ORequest.EntityOrderRequest.Staff1.Person.SignatureImage != null)
                    { 
                        <img src="@Url.Action("Photo", "Person", new { id = Model.ORequest.EntityOrderRequest.Staff1.Person.Id, area = "" })" alt="" style="max-width: 150px;" />
                    }
                </td>
            </tr>        
            <tr>
                <td colspan="5" align="center">
                    <input type="submit" class="btn green" value="Approve" /> &nbsp; 
                    <input type="button" class="btn green" value=" Reject " onclick="sendRequest('/RequestReview/LoadRejectOrder/@Model.ORequest.EntityOrderRequest.Id', 'popup-page', 'popup-loading'); CenterPopup();" />
                </td>
            </tr>
        </table>
    }
    <br />
</div>